package com.neusoft.yuejian12.yuejian_12.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian12.yuejian_12.R;
import com.neusoft.yuejian12.yuejian_12.activity.ClubCourseDetailActivity;
import com.neusoft.yuejian12.yuejian_12.javabean.CourseBean;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.neusoft.yuejian12.yuejian_12.constant.Constant.CLUB_COURSE_PHOTO_URL;

/**
 * Created by Administrator on 2017/10/12.
 */

public class ClubCourseAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContex;
    private List mDataList;
    private ViewHolder viewHolder;
    private LayoutInflater mLayoutInflater;
    public ClubCourseAdapter(Context mContext,List mDataList){
        this.mContex = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext())
                .inflate(R.layout.cardview_course, parent, false);
        return new ViewHolder(v);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final CourseBean entity = (CourseBean) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.course_name.setText(entity.getCc_name());
        //Log.d("sdf","activity_name");
        String pic = CLUB_COURSE_PHOTO_URL+entity.getCc_pic();
        if (!pic.equals("")){
            Picasso.with(mContex).load(pic).error(R.drawable.ic_add).into(viewHolder.course_pic);
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt("c_id",entity.getC_id());
                bundle.putString("c_name",entity.getC_name());
                bundle.putInt("cc_id",entity.getCc_id());
                bundle.putString("cc_name",entity.getCc_name());
                bundle.putString("cc_info",entity.getCc_info());
                bundle.putInt("cc_level",entity.getCc_level());
                bundle.putString("cc_pic",entity.getCc_pic());
                Intent intent=new Intent(mContex, ClubCourseDetailActivity.class);
                intent.putExtras(bundle);
                mContex.startActivity(intent);

            }
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView course_pic;
        TextView course_name;

        public ViewHolder(View itemView){
            super(itemView);
            course_name = (TextView) itemView.findViewById(R.id.course_name);
            course_pic = (ImageView) itemView.findViewById(R.id.course_pic);
        }
    }
}